package com.hczt.springcloud.eurekaclient.controller;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 把今天最好的表现当作明天最新的起点．．～
 * いま 最高の表現 として 明日最新の始発．．～
 * Today the best performance  as tomorrow newest starter!
 *
 * @author marvin.ma
 * @create 2017-10-20 17:00
 * @desc 调试controller
 **/
@RestController
public class HiController {

    private static final Logger logger = LoggerFactory.getLogger(HiController.class);

    @Value("${server.port}")
    private String port;

    @HystrixCommand(fallbackMethod = "hiError")
    @GetMapping("/hi")
    public String home(@RequestParam String name) {
        logger.info("Get response from {}", port);
        return "Hi "+ name + ",\n I am from port:" + port;
    }

    public String hiError(String name) {
        return "hi," + name + ",sorry, error!";
    }
}
